import Vue from "vue"
import VueRouter from "vue-router"



// 在全局注册声明使用VueRouter
Vue.use(VueRouter)


//1 路由组件

import errorpages from "@/views/errorpages/route"
import mainRoute from "@/views/main/route"
import loginRoute from '@/views/logins/route'
//定义路由选项
const routes = [ 
  {
    path:"/",
    redirect: '/guide'
  },
  {
    path: '/guide',
    name: 'guide',
    component: () => import('@/views/guide/guide.vue')
  }, 
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search/search.vue')
  }, 
  {
    path: '/city',
    name: 'city',
    component: () => import('@/views/city/city.vue')
  }, 
  ...loginRoute, 
  ...errorpages,
  ...mainRoute,
  {
    path:'*',
    redirect: "/404"
  },
  
]

// 3. 创建路由
const router = new VueRouter({
  mode:'hash',
  routes,
  base:""
})

router.beforeEach((to, from, next) => {
//to and from are Route Object,next() must be called to resolve the hook}
  next()
})
// 4. 挂载到根实例
export default router;